// V-backend/src/models/Registration.js
module.exports = (sequelize, DataTypes) => {
  const Registration = sequelize.define('Registration', {
    registration_id: {
      type: DataTypes.INTEGER,
      primaryKey: true,
      autoIncrement: true
    },
    audience_id: {
      type: DataTypes.INTEGER,
      allowNull: false
    },
    activity_id: {
      type: DataTypes.INTEGER,
      allowNull: false
    },
    status: {
      type: DataTypes.ENUM('registered', 'attended', 'cancelled'),
      defaultValue: 'registered'
    },
    registration_time: {
      type: DataTypes.DATE,
      defaultValue: DataTypes.NOW
    }
  }, {
    tableName: 'v_registration',
    timestamps: true,
    underscored: true,
    indexes: [
      {
        unique: true,
        fields: ['audience_id', 'activity_id']
      }
    ]
  });

  Registration.associate = function(models) {
    Registration.belongsTo(models.Audience, { 
      foreignKey: 'audience_id',
      as: 'audience'
    });
    
    Registration.belongsTo(models.Activity, { 
      foreignKey: 'activity_id',
      as: 'activity'
    });
  };

  return Registration;
};